<template>
	<view class="big_view">
		<view class="titles"><b>{{obj.title}}</b></view>
		<view class="texts">
			<rich-text :nodes="texts" class="imgs_big"></rich-text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				obj: {},
				texts: ""
			}
		},
		methods: {

		},
		onLoad: function(option) { //option为object类型，会序列化上个页面传递的参数
			function replace_Rich_text(html) {
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					match = match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/, '').replace(/\style='[^']+'/gi,
						'');
					match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
					match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
					return match;
				});
				let newContent1 = html.replace(/<div[^>]*>/gi, function(match, capture) {
					match = match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/, '').replace(/\style='[^']+'/gi,
						'');
					match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
					match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
					return match;
				});
				let newContent2 = html.replace(/<table[^>]*>/gi, function(match, capture) {
					match = match.replace(/style\s*?=\s*?([‘"])[\s\S]*?\1/, '').replace(/\style='[^']+'/gi,
						'');
					match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
					match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
					return match;
				});
				newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
					match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi,
						'max-width:100%;');
					return match;
				});
				newContent = newContent.replace(/<br[^>]*\/>/gi, '');
				newContent = newContent.replace(/\<img/gi,
					'< img style="max-width:414px;height:auto;display:block;margin-top:0;margin-bottom:0;"');
				return newContent;
			}
			uni.request({
				url: `http://111.67.198.176:8112/shop/notice/info/${JSON.parse(decodeURIComponent(option.item))}`,
				method: "get",
				dataType: "json",
				success: (res) => {
					this.obj = res.data
					this.texts = replace_Rich_text(res.data.content)
				}
			})
		}
	}
</script>

<style>
	.big_view {
		width: 100%;
		background: white;
	}

	.titles {
		width: 100%;
		padding: 10px;
		box-sizing: border-box;
	}
</style>
